﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ThouShaltNotBrick.Models;
using Microsoft.Xna.Framework.Content;

namespace ThouShaltNotBrick.PipelineExtension.Readers
{
    public sealed class BrickTypesContentTypeReader : ContentTypeReader<BrickTypesData>
    {
        #region Overriden Methods
        protected override BrickTypesData Read(ContentReader pInput, BrickTypesData pExistingInstance)
        {
            // NUMBER OF BRICK TYPES (int)
            //   NAME (string)
            //   NUMBER OF BRICK STATES (int)
            //     NAME (string)

            int numBrickTypes = pInput.ReadInt32();
            List<BrickTypeData> brickTypeList = new List<BrickTypeData>(numBrickTypes);
            for (int i = 0; i < numBrickTypes; i++)
            {
                string brickTypeName = pInput.ReadString();

                int numBrickStates = pInput.ReadInt32();
                List<string> brickStateList = new List<string>();
                for (int j = 0; j < numBrickStates; j++)
                {
                    string brickStateName = pInput.ReadString();
                    brickStateList.Add(brickStateName);
                }

                BrickTypeData brickType = new BrickTypeData(brickTypeName, brickStateList);
                brickTypeList.Add(brickType);
            }

            BrickTypesData brickTypes = new BrickTypesData(brickTypeList);
            return brickTypes;
        }
        #endregion
    }
}